home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / tools / czesc_2 / interfaces / willy-ttx / quicksort-source / listreq.c next >
C/C++ Source or Header  |  1992-11-24  |  4KB  |  179 lines

  1. /** listreq.c
  2. *
  3. *   A GadTools List requester
  4. *
  5. *   Willy Langeveld, Early 1992.
  6. *
  7. **/
  8. /*
  9. *   Standard includes for SAS C.
  10. */
  11. #include <exec/types.h>
  12. #include <exec/exec.h>
  13. #include <intuition/intuitionbase.h>
  14. #include <intuition/gadgetclass.h>
  15. #include <libraries/gadtools.h>
  16. #include <graphics/gfxbase.h>
  17. #include <graphics/text.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <ctype.h>
  22. #include <proto/all.h>
  23. /*
  24. *   The layout of the requester
  25. */
  26. #define MARGIN           10
  27. #define GADGET_SPACING    5
  28. /*
  29. *   The library we need
  30. */
  31. extern struct Library *GadToolsBase;
  32. /*
  33. *   Use Topaz-80 font.
  34. */
  35. static struct TextAttr topaz80 = { "topaz.font", 8, 0, 0 };
  36. /*
  37. *   Prototype
  38. */
  39. struct Node *ListRequest(struct Screen *, struct List *, long, long, long, long);
  40. /*
  41. *   quitflag values
  42. */
  43. #define NOTDONE  0
  44. #define NOCHANGE 1
  45. #define CHANGE   2
  46.  
  47.  
  48. /**
  49. *
  50. *
  51. **/
  52. struct Node *ListRequest(scr, list, x, y, width, height)
  53. struct Screen *scr;
  54. struct List *list;
  55. long x, y, width, height;
  56. {
  57.    struct VisualInfo *vi = NULL;
  58.    struct Gadget *glist = NULL, *gad, *gadget;
  59.    struct NewGadget ng;
  60.    struct Window *w = NULL;
  61.    long top, quitflag = NOTDONE;
  62.    ULONG class;
  63.    WORD code, selected;
  64.    struct IntuiMessage *msg;
  65.    struct Node *n = NULL;
  66. /*
  67. *   Check args
  68. */
  69.    if (width < 80)  width = 80;
  70.    if (height < 70) height = 70;
  71. /*
  72. *   Get screen info
  73. */
  74.    if (scr) {
  75.       if (((scr->Flags & SCREENTYPE) == PUBLICSCREEN) ||
  76.           ((scr->Flags & SCREENTYPE) == CUSTOMSCREEN)   ) {
  77.          vi = GetVisualInfoA(scr, NULL);
  78.       }
  79.    }
  80. /*
  81. *   Otherwise get access to the WorkBench screen
  82. */
  83.    if (vi == NULL) {
  84.       scr = LockPubScreen(NULL);
  85.       if (scr == NULL) goto cleanup;
  86.  
  87.       vi = GetVisualInfoA(scr, NULL);
  88.       UnlockPubScreen(NULL, scr);
  89.    }
  90.  
  91.    if (vi == NULL) goto cleanup;
  92. /*
  93. *   Now open up the window
  94. */
  95.    w = OpenWindowTags(NULL,
  96.                       WA_Left,         (ULONG) x,
  97.                       WA_Top,          (ULONG) y,
  98.                       WA_Width,        (ULONG) width,
  99.                       WA_Height,       (ULONG) height,
  100.                       WA_IDCMP,        (ULONG) LISTVIEWIDCMP | CLOSEWINDOW,
  101.                       WA_Flags,        (ULONG) WINDOWCLOSE  | SMART_REFRESH |
  102.                                                WINDOWDRAG   | WINDOWDEPTH   |
  103.                                                ACTIVATE,
  104.                       WA_Title,        (ULONG) "Select item:",
  105.                       WA_CustomScreen, (ULONG) scr,
  106.                       TAG_DONE);
  107.  
  108.    if (w == NULL) goto cleanup;
  109. /*
  110. *   Create the GadTools context
  111. */
  112.    gad = CreateContext(&glist);
  113.    if (gad == NULL) goto cleanup;
  114. /*
  115. *   A palette gadget
  116. */
  117.    top = w->BorderTop + GADGET_SPACING;
  118.  
  119.    ng.ng_LeftEdge   = MARGIN;
  120.    ng.ng_TopEdge    = top;
  121.    ng.ng_Width      = width - 2 * MARGIN;
  122.    ng.ng_Height     = height - top - GADGET_SPACING;
  123.    ng.ng_GadgetText = NULL;
  124.    ng.ng_GadgetID   = 1;
  125.    ng.ng_Flags      = 0;
  126.    ng.ng_TextAttr   = &topaz80;
  127.    ng.ng_VisualInfo = vi;
  128.    gad = CreateGadget(LISTVIEW_KIND, gad, &ng,
  129.                       GTLV_Labels,       list,
  130.                       GTLV_ScrollWidth,  18,
  131.                       TAG_DONE);
  132. /*
  133. *   Add the gadget list to the window.
  134. */
  135.    AddGList(w, glist, -1, -1, NULL);
  136.    RefreshGList(glist, w, NULL, -1);
  137.    GT_RefreshWindow(w, NULL);
  138. /*
  139. *   Wait for the user to do things
  140. */
  141.    while (quitflag == NOTDONE) {
  142.       WaitPort(w->UserPort);
  143.       while (msg = GT_GetIMsg(w->UserPort)) {
  144.          class  = msg->Class;
  145.          code   = (WORD) msg->Code;
  146.          gadget = (struct Gadget *) msg->IAddress;
  147.  
  148.          GT_ReplyIMsg(msg);
  149.  
  150.          if (class == GADGETUP) {
  151.             selected = code;
  152.             quitflag = CHANGE;
  153.          }
  154.          else if (class == CLOSEWINDOW) {
  155.             quitflag = NOCHANGE;
  156.          }
  157.       }
  158.    }
  159. /*
  160. *   This sequence shuts down the list requester
  161. */
  162. cleanup:
  163.    if (w)     CloseWindow(w);
  164.    if (glist) FreeGadgets(glist);
  165.    if (vi)    FreeVisualInfo(vi);
  166.  
  167.    if (quitflag == CHANGE) {
  168.       if (list) {
  169.          n = list->lh_Head;
  170.          while (selected--) n = n->ln_Succ;
  171.       }
  172.    }
  173.  
  174.    return(n);
  175. }
  176.  
  177.  
  178.  
  179.